import numpy as np


def rotate_vector_around_axis(v, axis, clockwise=True):
    # 转换为numpy数组
    v = np.array(v)

    # 旋转角度90度
    theta = np.pi / 2

    # 如果是顺时针旋转，角度为负
    if not clockwise:
        theta = -theta

    # 选择旋转矩阵
    if axis == 0:  # 围绕x轴旋转
        R = np.array([
            [1, 0, 0],
            [0, np.cos(theta), -np.sin(theta)],
            [0, np.sin(theta), np.cos(theta)]
        ])
    elif axis == 1:  # 围绕y轴旋转
        R = np.array([
            [np.cos(theta), 0, np.sin(theta)],
            [0, 1, 0],
            [-np.sin(theta), 0, np.cos(theta)]
        ])
    elif axis == 2:  # 围绕z轴旋转
        R = np.array([
            [np.cos(theta), -np.sin(theta), 0],
            [np.sin(theta), np.cos(theta), 0],
            [0, 0, 1]
        ])
    else:
        raise ValueError("Axis must be 0 (x), 1 (y), or 2 (z).")

    # 计算旋转后的向量
    rotated_vector = np.dot(R, v)

    # 将结果四舍五入并转换为整数
    return np.round(rotated_vector).astype(int).tolist()


def rotate_vector_around_axis_optimized(v: list, axis: int, clockwise=True):
    x, y, z = v

    def mix(x, y, clockwise: bool):
        flag = x * y * (1 if clockwise else -1)
        if flag == 1:
            return x, -y
        else:
            return -x, y

    if axis == 0:  # x
        z, y = mix(z, y, clockwise)
    elif axis == 1:  # y
        x, z = mix(x, z, clockwise)
    elif axis == 2:
        y, x = mix(y, x, clockwise)
    else:
        raise ValueError(f"axis参数错误 - {axis}")

    return [x, y, z]


# 示例使用
v = [1, -1, 1]  # 要旋转的向量
axis = 0  # 旋转轴 (1, 0, 0)
rotated_vector = rotate_vector_around_axis(v, axis, clockwise=True)
rotated_vector2 = rotate_vector_around_axis_optimized(v, axis, clockwise=True)
print(rotated_vector, rotated_vector2)  # 输出: [1, 1, -1]
